import api from './api';

/**
 * CRM服务 - 提供CRM相关功能
 */
const crmService = {
  /**
   * 添加联系人到CRM
   * @param {Object} crmData - CRM联系人数据
   * @param {string} crmData.name - 联系人姓名
   * @param {string} crmData.phone - 联系人电话
   * @param {string} crmData.product - 关注的产品
   * @param {string} crmData.quantity - 产品数量
   * @param {string} crmData.location - 地区
   * @param {string} crmData.notes - 备注
   * @returns {Promise<Object>} - 添加结果
   */
  addContact: async (crmData) => {
    const response = await api.post('/contacts/crm/customers', crmData);
    return response.data;
  },

  /**
   * 获取CRM联系人列表
   * @returns {Promise<Array>} - CRM联系人列表
   */
  getAllContacts: async () => {
    const response = await api.get('/contacts/crm/customers');
    return response.data;
  },

  /**
   * 更新CRM联系人信息
   * @param {string} id - 联系人ID
   * @param {Object} crmData - 更新的CRM数据
   * @returns {Promise<Object>} - 更新结果
   */
  updateContact: async (id, crmData) => {
    const response = await api.put(`/contacts/crm/customers/${id}`, crmData);
    return response.data;
  },

  /**
   * 导出CRM数据为CSV
   * @returns {Promise<Blob>} - CSV文件Blob
   */
  exportData: async () => {
    const response = await api.get('/contacts/crm/customers/export', {
      responseType: 'blob'
    });
    return response.data;
  }
};

export default crmService; 